package com.example.clublesson01.fragments

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.kf.lib_base.base.BaseActivity
import com.bw.kf.lib_base.base.BaseFragment
import com.example.clublesson01.R
import com.example.clublesson01.adapter.CommentAdapter
import com.example.clublesson01.adapter.TieDetailImgAdapter
import com.example.clublesson01.databinding.ActivityPlayCarDetailBinding
import com.example.clublesson01.fragments.playcart.PlayCartViewModel

@Route(path = "/app/fragments/PlayCarDetailActivity")
class PlayCarDetailActivity : BaseActivity<ActivityPlayCarDetailBinding,PlayCartViewModel>() {
    @Autowired
    @JvmField
    var postsId:String=""
    val imageAdapter = TieDetailImgAdapter()
    var commentAdapter = CommentAdapter()
    override fun iniView() {
        ARouter.getInstance().inject(this)
        viewModel.getPostDetail(postsId)

        viewModel.getTieComment(1,10,postsId)

        commentAdapter = CommentAdapter()
        binding.detailRvComment.adapter = commentAdapter
        binding.detailRvComment.layoutManager = LinearLayoutManager(this)
    }

    override fun iniData() {
        viewModel.tieDetailsuccess.observe(this){
            if(it.code==200){
//                binding.info = it.data.productInfo
//                attrId = it.data.productAttr[0].id.toString()
//                imgurl = it.data.productInfo.image

                binding.detailUsername.setText(it.data.model_nickname)
                binding.detailTime.setText(it.data.list_show_time)
                binding.detailConent.setText(it.data.content)

                binding.detailRvImg.adapter = imageAdapter
                binding.detailRvImg.layoutManager = GridLayoutManager(this,3)
                imageAdapter.data.addAll(it.data.image)
            }
        }

        viewModel.tieCommentsuccess.observe(this){
            if(it.code==200){
                commentAdapter.data.clear()
                commentAdapter.data.addAll(it.data.records)
                commentAdapter.notifyDataSetChanged()
            }
            ToastUtils.showShort(it.msg)
        }

        viewModel.tieCommentfail.observe(this){
            ToastUtils.showShort(it)
        }
    }

    override fun getViewModel(): Class<PlayCartViewModel> {
        return PlayCartViewModel::class.java
    }

    override fun Layoutid(): Int {
        return R.layout.activity_play_car_detail
    }

}